﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Avis.OutBoundAPI.Configuration;
using Avis.OutBoundAPI.Web;

namespace Avis.OutBoundAPI.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class OutBoundAPIDbContextFactory : IDesignTimeDbContextFactory<OutBoundAPIDbContext>
    {
        public OutBoundAPIDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<OutBoundAPIDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            OutBoundAPIDbContextConfigurer.Configure(builder, configuration.GetConnectionString(OutBoundAPIConsts.ConnectionStringName));

            return new OutBoundAPIDbContext(builder.Options);
        }
    }
}
